home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / CONTRIB / ASPI.ZIP / tapewrit.c < prev   
Encoding:
C/C++ Source or Header  |  1995-03-25  |  1.4 KB  |  83 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/stat.h>
  5. #include <io.h>
  6. #include <fcntl.h>
  7.  
  8. #include "aspi.h"
  9. #include "tape.h"
  10.  
  11. unsigned block_size = 20*512U;
  12. unsigned char *buffer;
  13.  
  14. int data_f;
  15.  
  16. void do_write(void)
  17. {
  18.   char cdb[6];
  19.   int stat, i, c;
  20.   long minblock, maxblock;
  21.   unsigned long total = 0;
  22.  
  23.   tape_rewind(1);
  24.   tape_set_blocksize(block_size);
  25.  
  26.   while (1)
  27.   {
  28.     int r = read(data_f, buffer, block_size);
  29.     if (r < 0)
  30.     {
  31.       perror("While reading data file");
  32.       return;
  33.     }
  34.     if (r == 0)
  35.       break;
  36.     memset(buffer+r, 0, block_size-r);
  37.     tape_write(buffer);
  38.  
  39.     total += r;
  40.     printf("  %s\r", tape_fmtnum(total));
  41.     fflush(stdout);
  42.   }
  43.   printf("\n");
  44.  
  45.   tape_write_filemark(3, 0);
  46. }
  47.  
  48. int main(int argc, char **argv)
  49. {
  50.   int target;
  51.   int stat;
  52.  
  53.   if (argc < 2)
  54.   {
  55.     printf("datwrite [-b blocks(512ea)] file\n");
  56.     printf("  ex: blocks = 20 is 10K\n");
  57.     return -1;
  58.   }
  59.  
  60.   if (strcmp(argv[1], "-b") == 0)
  61.   {
  62.     block_size = atoi(argv[2]) * 512UL;
  63.     argc -= 2;
  64.     argv += 2;
  65.   }
  66.   
  67.   data_f = open(argv[1], O_RDONLY|O_BINARY);
  68.   if (data_f < 0)
  69.   {
  70.     perror("Opening input data file");
  71.     exit(1);
  72.   }
  73.  
  74.   buffer = (char *)malloc(block_size);
  75.   aspi_buffer_length = block_size;
  76.   tape_open();
  77.   do_write();
  78.   tape_close();
  79.   
  80.   close(data_f);
  81.   return 0;
  82. }
  83.